package cn.com.lms.business.exam.persistence.repository;

import cn.com.lms.business.exam.persistence.entity.EmployeeExerciseSubject;

import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface EmployeeExerciseSubjectRepository extends BaseRepository<EmployeeExerciseSubject, Long> {

    @Query(value = "select SUBSTRING_INDEX(GROUP_CONCAT(answer order by create_time desc), ',', 1)  answer,es.subject_id as subjectId from bnz_exam_employee_exercise_subject es" +
            "  where es.subject_id in   (select sub.id from bnz_exam_question_subject sub where sub.question_id in(select question_id from bnz_exam_exercise_question eq where eq.exercise_id=es.exercise_id and sub.is_delete=0) ) " +
            " and  es.exercise_id = ?1 and es.employee_id=?2 GROUP BY subject_id", nativeQuery = true)
    List<Map<String,Object>> selectEmployeeExerciseSubjectByExerciseId(Long exerciseId,Long employeeId) ;

}
